package com.doit.demo04;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class test {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        My_call mc = new My_call();//创建My_call对象
        FutureTask<Integer> ft = new FutureTask<>(mc);//利用FutureTask类创建callable的实例化对象
        Thread t = new Thread(ft);

        t.start();

        System.out.println("准备获取数据");
        Integer num = ft.get();//如果没有获取到数据 就一直等待 一直到有数据为止
        System.out.println(num);

        new Thread(new FutureTask<Integer>(new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
                System.out.println("嘿嘿");
                return 10;
            }
        })).start();
    }
}
